package com.ssy.lingxi.order.model.vo.mobile.response;

import cn.hutool.core.util.StrUtil;
import com.ssy.lingxi.order.model.constant.BuyerInnerStatusEnum;
import com.ssy.lingxi.order.model.constant.OrderServiceContants;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 订单收发货批次
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-19
 */
public class MobileOrderDeliveryDetailVO implements Serializable {
    private static final long serialVersionUID = 2553399203735300353L;

    public MobileOrderDeliveryDetailVO(LocalDateTime deliverTime, Integer batchNo, String logisticsNo, String company, LocalDateTime receiptTime, String receiveBill, String selfCode, Integer buyerInnerStatus, List<MobileOrderDeliverProductDetailVO> products) {
        this.deliverTime = deliverTime == null ? "" : deliverTime.format(OrderServiceContants.DEFAULT_TIME_FORMATTER);
        this.batchNo = batchNo;
        this.logisticsNo = logisticsNo;
        this.company = company;
        this.receiptTime = receiptTime == null ? "" : receiptTime.format(OrderServiceContants.DEFAULT_TIME_FORMATTER);
        this.receiveBill = StrUtil.isEmpty(receiveBill) ? "" : receiveBill;
        this.selfCode = StrUtil.isEmpty(selfCode) ? "" : selfCode;
        this.innerStatus = buyerInnerStatus;
        this.innerStatusName = BuyerInnerStatusEnum.getNameByCode(buyerInnerStatus);
        this.showReceive = buyerInnerStatus.equals(BuyerInnerStatusEnum.BUYER_TO_RECEIVE.getCode());
        this.products = products.stream().distinct().sorted(Comparator.comparingLong(MobileOrderDeliverProductDetailVO::getDeliveryProductId)).collect(Collectors.toList());
    }

    /**
     * 发货时间，格式为yyyy-MM-dd HH:mm:ss
     */
    private String deliverTime;

    /**
     * 发货批次，顺序 +1
     */
    private Integer batchNo;

    /**
     * 物流单号
     */
    private String logisticsNo;

    /**
     * 物流公司名称
     */
    private String company;

    /**
     * 收货时间，格式为yyyy-MM-dd HH:mm:ss，如还没收货则为空字符串
     */
    private String receiptTime;

    /**
     * 收货回单url地址
     */
    private String receiveBill;

    /**
     * 自提码
     */
    private String selfCode;

    /**
     * 收货状态
     */
    private Integer innerStatus;

    /**
     * 收货状态名称
     */
    private String innerStatusName;

    /**
     * 是否显示“确认收货”按钮，true-是（可以收货），false-否（不能收货）
     */
    private Boolean showReceive;

    /**
     * 收发货商品列表
     */
    private List<MobileOrderDeliverProductDetailVO> products;

    public String getDeliverTime() {
        return deliverTime;
    }

    public void setDeliverTime(String deliverTime) {
        this.deliverTime = deliverTime;
    }

    public Integer getBatchNo() {
        return batchNo;
    }

    public void setBatchNo(Integer batchNo) {
        this.batchNo = batchNo;
    }

    public String getLogisticsNo() {
        return logisticsNo;
    }

    public void setLogisticsNo(String logisticsNo) {
        this.logisticsNo = logisticsNo;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getReceiptTime() {
        return receiptTime;
    }

    public void setReceiptTime(String receiptTime) {
        this.receiptTime = receiptTime;
    }

    public String getReceiveBill() {
        return receiveBill;
    }

    public void setReceiveBill(String receiveBill) {
        this.receiveBill = receiveBill;
    }

    public String getSelfCode() {
        return selfCode;
    }

    public void setSelfCode(String selfCode) {
        this.selfCode = selfCode;
    }

    public Integer getInnerStatus() {
        return innerStatus;
    }

    public void setInnerStatus(Integer innerStatus) {
        this.innerStatus = innerStatus;
    }

    public String getInnerStatusName() {
        return innerStatusName;
    }

    public void setInnerStatusName(String innerStatusName) {
        this.innerStatusName = innerStatusName;
    }

    public Boolean getShowReceive() {
        return showReceive;
    }

    public void setShowReceive(Boolean showReceive) {
        this.showReceive = showReceive;
    }

    public List<MobileOrderDeliverProductDetailVO> getProducts() {
        return products;
    }

    public void setProducts(List<MobileOrderDeliverProductDetailVO> products) {
        this.products = products;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        MobileOrderDeliveryDetailVO that = (MobileOrderDeliveryDetailVO) o;
        return Objects.equals(batchNo, that.batchNo);
    }

    @Override
    public int hashCode() {
        return Objects.hash(batchNo);
    }
}
